#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/3/5
import socket

ip_port = ("127.0.0.1", 9999)

sk = socket.socket()
sk.bind(ip_port)
sk.listen(5)  # 最大连接数

while True:
    print("server waiting...")
    conn, addr = sk.accept()  # 获取scoket实例和ip地址和端口

    client_data = conn.recv(1024)  # 收取数据 指定收取的数据长度

    print(str(client_data, "utf8"))

    conn.sendall(bytes("不要回答", encoding="utf8"))  # 返回消息给客户端

    while True:
        client_data = conn.recv(1024)
        if not client_data.decode():break
        print(str(client_data, "utf8"))
        server_response = input("\033[31:1m>>:\033[0m").strip()
        conn.send(bytes(server_response, "utf8"))

    conn.close()
